package com.gxar.file.server.base.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 环境枚举
 *
 * @author linsy
 * @version 1.0
 * @created 2023/7/13 14:13
 */
@Getter
public enum ActiveProfileEnum {
    DEV(0, "dev", "开发环境", TargetChannelEnum.NAS),
    TEST(1, "test", "测试环境", TargetChannelEnum.MIN_IO),
    PROD(2, "prod", "生产环境", TargetChannelEnum.OSS),
    ;
    private final Integer code;
    private final String name;
    private final String desc;
    private final TargetChannelEnum targetChannelEnum;

    ActiveProfileEnum(Integer code, String name, String desc, TargetChannelEnum targetChannelEnum) {
        this.code = code;
        this.name = name;
        this.desc = desc;
        this.targetChannelEnum = targetChannelEnum;
    }

    /**
     * 根据环境名称获取渠道源
     *
     * @param name 环境名称
     * @return 渠道源
     */
    public static TargetChannelEnum getChannelTargetByName(String name) {
        ActiveProfileEnum activeProfileEnum = Arrays.stream(ActiveProfileEnum.values()).filter(e -> e.getName().equals(name)).findFirst().orElse(null);
        if (Objects.nonNull(activeProfileEnum)) {
            return activeProfileEnum.getTargetChannelEnum();
        }
        return null;
    }

}
